<?php

// +----------------------------------------------------------------------
// | Apprh.Shop
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.apprh.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | Author: pp <124910168@qq.com>
// +----------------------------------------------------------------------

namespace app\home\controller\member;

use think\Db;

/**
 * Home后端-学习课件
 * Class Courseware
 * @package app\home\controller\member
 * @author pp <124910168@qq.com>
 * @date 2020/06/04 10:41
 */
class Courseware extends Admin
{
    public function _initialize()
    {
        parent::_initialize();
    }

    public function index(){
        $get = $this->request->get();
        $catid = input('cid', 2);//默认 图文 理论知识
        // halt($catid);
        
        $map = ['status' => 1, 'catid' => $catid];
        $m = $this->category->getValue(['id' => $catid], 'module');

        // 应用搜索条件
        foreach (['kw', 'aid', 'cid'] as $key) {
            if (isset($get[$key]) && $get[$key] !== '') {
                if(in_array($key, ['aid', 'cid'])){
                    $map[$key] = ['eq', $get[$key]];
                }else{
                    $map['title|desc|content'] = ['like', "%".$get[$key]."%"];
                }
            }
        }

        // $list = $this->demonstration->getPageLists($map, '', '');
        // halt($list);

        $list = Db::name($m)
        ->order('sort asc,updatetime desc')
        ->paginate(8);
        
        // 获取分页显示
        $page = $list->render();
        $list = $list->toArray();
        // halt($list['data']);

        $data = [
            'list' => $list['data'],
            'page' => $page,
            'kw' => !empty($get['kw']) ? $get['kw'] : '',
            'aid' => !empty($get['aid']) ? $get['aid'] : '',
            'nid' => !empty($get['nid']) ? $get['nid'] : '',
            'did' => !empty($get['did']) ? $get['did'] : '',
            'cid' => $catid,
        ];
        return $this->fetch('', $data);
    }
}
